package collectionFrame.Demo7_LinkedListExample;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TeacherProject {

    Map<String,String> teacherProjectMap = new HashMap<>();

    public void initTeacher(){
        teacherProjectMap.put("tom","java");
        teacherProjectMap.put("jerry","oracle");
        teacherProjectMap.put("john","oracle");
        teacherProjectMap.put("susan","jdbc");
        teacherProjectMap.put("jim","unix");
        teacherProjectMap.put("keven","jsp");
        teacherProjectMap.put("lucy","jsp");
    }

    public void addTeacher(String teacherName,String teacherProject){
        teacherProjectMap.put(teacherName,teacherProject);
    }

    public void modifyTeacher(String teacherName,String teacherProject){
        if(teacherProjectMap.containsKey(teacherName)){
            teacherProjectMap.replace(teacherName,teacherProject);
//            teacherProjectMap.put(teacherName,teacherProject);
        }else{
            System.out.println("没有可替换课程的老师");
        }

    }

    public void showAllTeacher(){

        Set<Map.Entry<String, String>> teachers = teacherProjectMap.entrySet();

        for (Map.Entry<String, String> teacher : teachers) {
            System.out.println("teacher:"+teacher.getKey());
            System.out.println("project:"+teacher.getValue());
        }

    }

    public void getTeacherByProject(String project){
        Set<Map.Entry<String, String>> teachers = teacherProjectMap.entrySet();

        for (Map.Entry<String, String> teacher : teachers) {
            if(teacher.getValue().equals(project)){
                System.out.println(teacher.getKey());
            }
        }
    }


    public static void main(String[] args) {
        TeacherProject teacherProject = new TeacherProject();

        teacherProject.initTeacher();
        System.out.println(teacherProject.teacherProjectMap);

        teacherProject.addTeacher("ztq","LOL");
        System.out.println(teacherProject.teacherProjectMap);

        teacherProject.modifyTeacher("lucy","王者荣耀");
        System.out.println(teacherProject.teacherProjectMap);

        teacherProject.showAllTeacher();

        teacherProject.getTeacherByProject("oracle");
    }

}
